package cn.wolfcode;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/*
* 代码生成器
* */
public class CodeGenerator {

    public static void main(String[] args) {

        //mp代码生成器
        AutoGenerator ag = new AutoGenerator();

        //全局配置
        GlobalConfig gc = new GlobalConfig();
        //设置主键生成策略 （Auto是自增）
        gc.setIdType(IdType.AUTO);
        gc.setControllerName("%sController");
        gc.setServiceName("I%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setMapperName("%sMapper");
        gc.setAuthor("c1eye");
        //获取当前项目路径
        String path = System.getProperty("user.dir");
//        System.out.println(path);
        gc.setOutputDir(path + "/trip-core/src/main/java");
        //全局配置设置给代码生成器
        ag.setGlobalConfig(gc);

        DataSourceConfig ds = new DataSourceConfig();
        ds.setDriverName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://101.43.163.178:3306/wolf2w40");
        ds.setUsername("root");
        ds.setPassword("root");
        ag.setDataSource(ds);

        PackageConfig pc = new PackageConfig();
        pc.setParent("cn.wolfcode");
        ag.setPackageInfo(pc);

        StrategyConfig sc = new StrategyConfig();
        sc.setColumnNaming(NamingStrategy.underline_to_camel);
        sc.setNaming(NamingStrategy.underline_to_camel);
        ag.setStrategy(sc);

        ag.execute();


    }

}
